package cn.corffen.test.algorithm.design;

import java.util.Random;

public class DesignDemo {


    int[] numbers;
    int[] origin;
    private Random random = new Random();

    public DesignDemo(int[] nums) {
        numbers = nums;
        origin = nums.clone();
    }

    /**
     * Resets the array to its original configuration and return it.
     */
    public int[] reset() {
        numbers = origin.clone();
        return numbers;
    }

    /**
     * Returns a random shuffling of the array.
     */
    public int[] shuffle() {
        int len = numbers.length;
        for (int i = 0; i < len; i++) {
            int r = random.nextInt(len - i) + i;
            int temp = numbers[i];
            numbers[i] = numbers[r];
            numbers[r] = temp;
        }
        return numbers;
    }
}
